package test;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;

public class Chronometre {
	
	private Timer timer;
	private long time;
	
	public Chronometre(){
		time = 0;
		
		ActionListener aL = new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				time++;
			}
		};
		
		timer = new Timer(1, aL);
		timer.setRepeats(true);
	}
	
	public synchronized void start(){
		timer.start();
	}
	
	public synchronized void stop(){
		if(timer.isRunning()){
			timer.stop();
		}
	}
	
	public synchronized void restart(){
		if(timer.isRunning()){
			timer.stop();
		}
		
		time = 0;
	}
	
	public synchronized long getTime(){
		return time;
	}
}
